package com.epoint.bookmanagement.action.borrowinfo;

import java.io.IOException;
import java.lang.reflect.Field;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.epoint.bookmanagement.bizlogic.borrowinfo.BorrowInfoService;
import com.epoint.bookmanagement.bizlogic.borrowinfo.domain.BorrowInfo;
import com.epoint.bookmanagement.utils.RequestUtils;

/**
 * Servlet implementation class BorrowInfoAddAction
 */
@WebServlet("/borrowinfoaddaction")
public class BorrowInfoAddAction extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	BorrowInfoService borrowInfoService = new BorrowInfoService();
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BorrowInfoAddAction() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
//		response.getWriter().append("Served at: ").append(request.getContextPath());
		String requestMethod = request.getParameter("method");
		String json = RequestUtils.reflectInvokMethod(requestMethod, request,"com.epoint.bookmanagement.action.borrowinfo.BorrowInfoAddAction");
		response.getWriter().write(json);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}
	
	
	/**
	 * 新增借阅信息
	 * @param request 请求信息
	 * @return
	 */
	public String addBorrowInfo(HttpServletRequest request) {
		String data = request.getParameter("data");
		BorrowInfo borrowInfo = JSON.parseObject(data, BorrowInfo.class);
		int i = borrowInfoService.addBorrowInfo(borrowInfo);
		if (i > 0) {
			return "借阅成功";
		} else {
			return "借阅失败";
		}
	}

}
